/*************************************************************
 * File: Role.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Feb 20, 2013
 * Description: 
 ************************************************************/

package snow.biz.security.model;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import snow.biz.basic.model.Persistence;
import snow.biz.system.model.User;
import snow.core.enums.Status;
import snow.core.exceptions.BusinessException;
import snow.core.toolkit.Validator;

/**
 * 系统角色
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
@SuppressWarnings("serial")
public class Role extends Persistence<Integer> {

	private String name; // 角色名称
	private String desc; // 角色描述

	private Map<Privilege, Persistence<Integer>> privileges; // 权限信息

	protected Role() {
	}

	public Role(User createUser, String name, String desc, Set<Privilege> privileges) throws BusinessException {
		this(createUser, Status.FAILURE, name, desc, privileges);
	}

	public Role(User createUser, Status status, String name, String desc, Set<Privilege> privileges) throws BusinessException {
		super(createUser, status);
		Validator.notEmpty(privileges, "", "");
		
	}

	public void addPrivilege(Privilege privilege) throws BusinessException {
	}

	public String getDesc() {
		return this.desc;
	}

	public String getName() {
		return this.name;
	}

	public Set<Privilege> getPrivileges() {
		return Collections.unmodifiableSet(this.privileges.keySet());
	}
	
	public boolean contains(Privilege privilege) {
		return privilege != null && this.privileges.containsKey(privilege);
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPrivileges(Set<Privilege> privileges) {
	}
}
